package com.hongdee.crm.card.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.common.util.TokenUtil;
import com.hongdee.crm.card.service.ITCrmCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by Liu XiaoLong
 * Date: 2018/2/27.
 * Remark:
 */
@RestController
@RequestMapping("/crm/card")
public class TCrmCardController {

    @Autowired
    private ITCrmCardService itCrmCardService;

    @RequestMapping("/impPage")
    @ResponseBody
    public Map impPage(@RequestParam(name = "uid", defaultValue = "") String uid,
                       @RequestParam(name = "token", defaultValue = "") String token,
                       @RequestParam(name = "start", defaultValue = "0") String start,
                       @RequestParam(name = "limit", defaultValue = "50") String limit) throws Exception {
        String oid = TokenUtil.getCompanyId(uid);
        Map map = this.itCrmCardService.impPage(start, limit, oid);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * @Name: 全部确认
     * @Author: Liu XiaoLong
     * @Date: 2018/2/28 16:01
     * @Remark:
     */
    @RequestMapping("/impConfirmAll")
    @ResponseBody
    public ResultEntity impConfirmAll(@RequestParam(name = "uid", defaultValue = "") String uid,
                                      @RequestParam(name = "token", defaultValue = "") String token
    ) throws Exception {
        this.itCrmCardService.impConfirmAll(uid);
        ResultEntity res = new ResultEntity();
        res.setSuccess(true);
        res.setMsg("确认成功！");
        return res;
    }

    /**
     * @Name: 全部删除
     * @Author: Liu XiaoLong
     * @Date: 2018/2/28 16:56
     * @Remark:
     */
    @RequestMapping("/impDelAll")
    public ResultEntity impDelAll(@RequestParam(name = "uid", defaultValue = "") String uid,
                                  @RequestParam(name = "token", defaultValue = "") String token) throws Exception {
        this.itCrmCardService.impDelAll(uid);
        ResultEntity res = new ResultEntity();
        res.setSuccess(true);
        res.setMsg("删除成功！");
        return res;
    }

    /**
     * @Name: 卡信息查询
     * @Author: Liu XiaoLong
     * @Date: 2018/3/1 10:36
     * @Remark:
     */
    @RequestMapping("/queryCardPage")
    public Map queryCardPage(
            @RequestParam(name = "uid", defaultValue = "") String uid,
            @RequestParam(name = "token", defaultValue = "") String token,
            @RequestParam(name = "start", defaultValue = "") String start,
            @RequestParam(name = "limit", defaultValue = "50") String limit,
            @RequestBody Map data) throws  Exception {

        Map map = this.itCrmCardService.queryCardPage(data,uid,start,limit);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }
}
